﻿using AutoMapper;
using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.Commands.DepartmentCommands
{
    public class DepartmentCreateHandler : IRequestHandler<DepartmentCreateCommand, Result>
    {
        private readonly IBaseRepository<Departments> departmentbaseRepository;
        private readonly IMapper mapper;

        public DepartmentCreateHandler(IBaseRepository<Departments> departmentbaseRepository, IMapper mapper)
        {
            this.departmentbaseRepository = departmentbaseRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 部门添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(DepartmentCreateCommand request, CancellationToken cancellationToken)
        {
            var result= new Result() { Code=(int)CodeEnum.add};
            Departments departments=mapper.Map<Departments>(request);




            var list= departmentbaseRepository.Add(departments);
            result.Code = list;
            return result;
        }
    }
}
